package com.ynding.spring.idea.ddd.core.model.wechat.dp;

import com.ynding.spring.idea.ddd.core.model.bo.Identifier;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


/**
 * <p> 电话号码 DP</p>
 *
 * @author ynding
 * @version 2022/4/26
 **/
@ApiModel(value = "PhoneNumber", description = "电话号码")
@Data
public class PhoneNumber implements Identifier {

    @ApiModelProperty("手机号")
    private final String number;

    private final String pattern = "^0?[1-9]{2,3}-?\\d{8}$";


    /**
     * 仅使用含参构造器
     * @param number 手机号
     *
     */
    public PhoneNumber(String number) {
        if (number == null) {
            throw new RuntimeException("number 不能为空");
        }
        if (isValid(number)){
            throw new RuntimeException("number 格式错误");
        }
        this.number = number;
    }

    /**
     * 验证手机号格式
     * @param number 手机号
     * @return
     */
    private boolean isValid(String number) {
        return number.matches(pattern);
    }

    /**
     * 获取号码地区编码
     * @return
     */
    public String getAreaCode(){
        // ...
        return null;
    }

    public String getOperatorCode(PhoneNumber phone){
        // ...
        return null;
    }

}
